package com.work.work4;

public class Main {
    public static void sort(Student[] students) {
        Student temp = null;
        for (int i = 0; i < students.length; i++) {
            for (int j = 0; j < students.length - i - 1; j++) {
                if (students[j].compareTo(students[j + 1]) == -1) {
                    temp = students[j];
                    students[j] = students[j + 1];
                    students[j + 1] = temp;
                }
            }
        }
    }
    public static void main(String[] args) {
        Student[] students =new Student[5];  //定义学生对象数组
        students[0]=new Student(1,"小李",80);
        students[1]=new Student(2,"小青",90);
        students[2]=new Student(3,"小王",85);
        students[3]=new Student(4,"小华",75);
        students[4]=new Student(5,"小明",96);
        System.out.println("排序前");
        for (Student student : students) {
            System.out.println(student.toString());
        }
        sort(students);
        System.out.println("排序后");
        for (Student student : students) {
            System.out.println(student.toString());
        }
    }
}
